package com.itcam.phaselist.list_;

/*
添加10个以上的元素(比如String "hello" )，在2号位插入一个元素"javaCollection"，
获得第5个元素，删除第6个元素，修改第7个元素，在使用迭代器遍历集合，

要求:使用List的实现类ArrayList完成。
*/

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListExercise {

    public static void main(String[] args) {
        List list = new ArrayList();
        for (int i = 0; i < 13; i++) {
            list.add("hello" + i);
        }
        System.out.println("list = " + list);

        list.add(1, "javaCollection");
        System.out.println("after add list = " + list);

        System.out.println("list NO.5 = " + list.get(4));

        System.out.println("remove list NO.6 = " + list.remove(5));

        list.set(6, "cammy");
        System.out.println("set list NO.7 = " + list);

        Iterator iterator = list.iterator();
        System.out.print("iterator list = ");
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.print(next + "\t");
        }
    }
}
